package com.tvunetworks.center.user.schedule;

import com.tvunetworks.center.common.util.Result;
import com.tvunetworks.center.common.util.ResultUtil;
import com.tvunetworks.center.user.service.UserInstanceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @program: tvucc-aggregator
 * @description: UserInstanceJob
 * @author lebronchen
 * @create: 2020-08-26 14:42
 **/
@RestController
@RequestMapping("/schedule")
@Slf4j
public class UserInstanceJob {

    @Autowired
    private UserInstanceService userInstanceService;

    /**
     *
     * @return Result
     */
    @PostMapping("/shutdownSchedule")
    public Result shutdownSchedule(){
        userInstanceService.shutdownSchedule();
        return ResultUtil.success();
    }

    /**
     * 开关机流程失败导致 TPC 设备需要绑定和释放的补救任务
     * @return Result
     */
    @PostMapping("/remedyUserInstancePeerId")
    public Result remedyUserInstancePeerId(){
        userInstanceService.remedyUserInstancePeerId();
        return ResultUtil.success();
    }

    /**
     * 定时查询实例如果被关闭了，修改 UserInstance 为关闭状态
     * @throws  IOException 編譯一場
     * @return Result
     */
    @PostMapping("/syncInstanceStatus")
    public Result syncInstanceStatus() throws IOException {
        userInstanceService.syncInstanceStatus();
        return ResultUtil.success();
    }

    /**
     *
     * @return Result
     */
    @PostMapping("/sendRunningEmail")
    public Result sendRunningEmail(){
        log.error("UserInstanceSchedule sendRunningEmail start");
        userInstanceService.sendRunningInstanceEmailToSupport();
        return ResultUtil.success();
    }
}
